import React, { useState } from "react";
//自定义Hook：提取公共的逻辑和操作
//自定义useParState，用于修改部分状态
const useParState=function useParState(initial){
  //initial:初始状态值(对象，包含需要的多个状态)
  let [state,setState]=useState(initial)
  //定义支持部分状态修改的办法
  const setParState = (parState)=>{
    setState({
      ...state,
      ...parState
    });
  }
  return [state,setParState]
}
export default function CustomHook(props){
  let [state,setState]=useParState({
    x:10,
    y:20
  })
  const handler=()=>{
    setState({
      x:state.x+10
    });
  }
  return <div>
    <span>{state.x}</span>
    <span>{state.y}</span>
    <button onClick={handler}>修改部分状态</button>
  </div>
}
